package com.ruoyi.wms.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.mapper.StockPdaOutMapper;
import com.ruoyi.wms.domain.StockPdaOut;
import com.ruoyi.wms.service.IStockPdaOutService;

/**
 * PDA出库存Service业务层处理
 *
 * @author ruoyi
 * @date 2025-10-28
 */
@Service
public class StockPdaOutServiceImpl implements IStockPdaOutService {
    @Autowired
    private StockPdaOutMapper stockPdaOutMapper;

    /**
     * 查询PDA出库存
     *
     * @param id PDA出库存主键
     * @return PDA出库存
     */
    @Override
    public StockPdaOut selectStockPdaOutById(String id) {
        return stockPdaOutMapper.selectStockPdaOutById(id);
    }

    /**
     * 查询PDA出库存列表
     *
     * @param stockPdaOut PDA出库存
     * @return PDA出库存
     */
    @Override
    public List<StockPdaOut> selectStockPdaOutList(StockPdaOut stockPdaOut) {
        return stockPdaOutMapper.selectStockPdaOutList(stockPdaOut);
    }

    /**
     * 新增PDA出库存
     *
     * @param stockPdaOut PDA出库存
     * @return 结果
     */
    @Override
    public int insertStockPdaOut(StockPdaOut stockPdaOut) {

        stockPdaOut.setId(MD5Utils.md5(stockPdaOut.getBatchNum()));
        stockPdaOut.setCreateUser(SecurityUtils.getUsername());
        stockPdaOut.setCreateDate(DateUtils.getCurrentTime());
        stockPdaOut.setUpdateDate(DateUtils.getCurrentTime());
        return stockPdaOutMapper.insertStockPdaOut(stockPdaOut);
    }

    /**
     * 修改PDA出库存
     *
     * @param stockPdaOut PDA出库存
     * @return 结果
     */
    @Override
    public int updateStockPdaOut(StockPdaOut stockPdaOut) {

        int updateResult = 0;
        if (StringUtils.isEmpty(stockPdaOut.getId())) {
            updateResult = insertStockPdaOut(stockPdaOut);
        }
        stockPdaOut.setUpdateDate(DateUtils.getCurrentTime());
        updateResult = stockPdaOutMapper.updateStockPdaOut(stockPdaOut);
        if (0 == updateResult) {
            updateResult = insertStockPdaOut(stockPdaOut);
        }


        return updateResult;


    }

    /**
     * 批量删除PDA出库存
     *
     * @param ids 需要删除的PDA出库存主键
     * @return 结果
     */
    @Override
    public int deleteStockPdaOutByIds(String[] ids) {
        return stockPdaOutMapper.deleteStockPdaOutByIds(ids);
    }

    /**
     * 删除PDA出库存信息
     *
     * @param id PDA出库存主键
     * @return 结果
     */
    @Override
    public int deleteStockPdaOutById(String id) {
        return stockPdaOutMapper.deleteStockPdaOutById(id);
    }
}
